package jastgen.nodes;

import java.util.List;
import static java.util.Collections.*;

public class ClassDef {

	private final Type        className;
	private final Type        interfaceName;
	private final int         interfaceNum;  // 同じインターフェースを実装した中で何番目か
	private final List<Field> fields;

	public ClassDef(
			final Type        className,
			final Type        interfaceName,
			final int         interfaceNum,
			final List<Field> fields)
	{
		this.className = className;
		this.interfaceName = interfaceName;
		this.interfaceNum = interfaceNum;
		this.fields = unmodifiableList(fields);
	}

	public String getName() {
		return className.toString();
	}

	public String getBaseName() {
		return className.getName();
	}

	public String getTypeParamsString() {
		return className.getTypeParamsString();
	}

	public String getTypeParams() {
		return className.paramsToString();
	}

	public String paramsToStringQ() {
		return className.paramsToStringQ();
	}

	public String getInterfaceName() {
		return interfaceName.toString();
	}

	public String getInterfaceBaseName() {
		return interfaceName.getName();
	}

	public boolean hasInterface() {
		return interfaceName != null;
	}

	/*
	public String interfaceParamsToStringQ() {
		return interfaceName.paramsToStringQ();
	}
	*/


	public String getNameQsIF() {
		return interfaceName.toStringQs();
	}

	public String getNameQs() {
		return className.toStringQs();
	}





	// TODO: 改名 (getNumInInterface)
	public int getInterfaceNum() {
		return interfaceNum;
	}

	public List<Field> getFields() {
		return fields;
	}

	private Type getInterfaceOrClassNameImpl() {
		return (interfaceName != null)
				? interfaceName
				: className;
	}

	public String getInterfaceOrClassName() {
		return getInterfaceOrClassNameImpl().toString();
	}

	public String getInterfaceOrClassBaseName() {
		return getInterfaceOrClassNameImpl().getName();
	}

	public boolean hasFieldWithBody() {
		for(final Field f : fields)
			if(f.hasBody())
				return true;
		return false;
	}

	// ignoredではないフィールドが存在すればtrue
	public boolean hasNormalFields() {
		for(final Field f : fields)
			if(!f.isIgnored())
				return true;
		return false;
	}
}
